import { css_disnone } from '../../../css';
import { remove_class } from '../../../global/element/class_operate/Func';
import { create_staticCssTxt_mana } from '../../../global/element/css/setStaticCsstxt';
import { endsTimeAnimation } from '../../../global/Func/uniFunc/Func';
import { element_add_anima } from './Classes/cla_element_add_anima';
import {
  staticCss_element_add_id_prefix,
  staticCss_element_add_space,
} from './DataDefine/sourceData';

/**
 * static css 管理
 * element add
 */
const StaticCss_element_add = create_staticCssTxt_mana(
  staticCss_element_add_space
);

/**
 * 增加 元素 应用 引入 动画
 * @param {HTMLElement} elt
 */
function element_add(elt) {
  let element_add_obj = new element_add_anima(elt);

  // 创建 对应消失 方向的 css
  StaticCss_element_add.setStaticCssTxt(
    staticCss_element_add_id_prefix + elt.id,
    element_add_obj.calculate_staticCss()
  );

  // 应用动画
  requestAnimationFrame(() => {
    requestAnimationFrame(() => {
      remove_class(elt, css_disnone);
    });
    endsTimeAnimation(elt, element_add_obj.add_anima_cla);
  });
}

export { element_add };
